package com.example.springbootfastjson2.demo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.util.Map;
import java.util.Set;

/**
 * @program: springboot-fastjson2
 * @description: 2
 * @author: XianJin.Lu
 * @create: 2021-09-08 18:00
 **/
public class demo02 {
    public static void main(String[] args) {
        String s2= "{hello:\"world\",head : { \"cmdType\":2, \"cmdSn\":2222 } ,data : { \"devId\":0,\"operType\":0,\"doorIndex\":1 } }";

        JSONObject jsonObject = JSON.parseObject(s2);

        Set<Map.Entry<String, Object>> entries = jsonObject.entrySet();

        for (Map.Entry<String, Object> entry : entries) {
            String key = entry.getKey();
            System.out.println(key);
            Object value = entry.getValue();
            String s = JSON.toJSONString(value);
            if(s.indexOf('{')>=0) {
                JSONObject jsonObject1 = JSON.parseObject(s);
            }
        }


        Object data = jsonObject.get("data");


        String s = JSON.toJSONString(data);
        System.out.println(s);

        JSONObject jsonObject1 = JSON.parseObject(s);
        System.out.println(jsonObject1.get("devId"));


    }
}
